#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
char pt[100];
char ct1[100];
char ct2[100];

vector<int> adj[100];
vector<int> finalAdj[100];
int matched[100];
bool visited[100];

bool search(int x) {
	for (unsigned int i=0; i<finalAdj[x].size(); ++i) {
		int adj = finalAdj[x][i];
		if (visited[adj]) continue;
		else {
			visited[adj] = true;
			if (matched[adj]==-1 || search(matched[adj])) {
				matched[adj] = x;
				return true;
			}
		}
	}
	return false;
}

void findPerm(void) {
	char gpt[100];
	char gct1[100];
	int app[100];
	int n = strlen(pt);
	int gn = 0;
	bool ok = true;
	char tmp[100];
	strcpy(tmp, pt);
	strcpy(pt, ct1);
	strcpy(ct1, tmp);
	for (int k=1; k<=n; ++k) {
		if (k == 4) {
			int debug = 1;

		}
		ok = false;
		strcpy(gpt, pt);
		strcpy(gct1, ct1);
		gn = 0;
		int bakN = n;
		n = n - n%k;
		for (int i=0; i<n; i+=k) {
			sort(gpt+i, gpt+min(n,i+k));
			sort(gct1+i, gct1+min(n,i+k));
			++gn;
		}
		if (strncmp(gpt,gct1,n) == 0) {
			ok = true;
			//cout << k << endl;
			for (int i=0; i<k; ++i) adj[i].clear();
			for (int i=0; i<n; i+=k) {
				for (int j=i+0; j<min(i+k,n); ++j)
					for (int t=i+0; t<min(i+k,n); ++t)
						if (pt[j] == ct1[t])
							adj[j-i].push_back(t-i);
			}
			
			for (int i=0; i<k; ++i) {
				finalAdj[i].clear();
				memset(app, 0, sizeof(int)*k);
				for (unsigned int j=0; j<adj[i].size(); ++j)
					++app[adj[i][j]];
				for (int j=0; j<k; ++j)
					if (app[j] == gn) finalAdj[i].push_back(j);
				if (finalAdj[i].size() == 0) {
					ok = false;
					break;
				}
			}

			if (!ok) {
				n = bakN;
				continue;
			}
			for (int i=0; i<k; ++i) {
				matched[i] = -1;
				visited[i] = false;
			}
			int cnt = 0;
			for (int i=0; i<k; ++i) {
				if (search(i)) ++cnt;
			}
			if (cnt == k) {
				ok = true;
				for (int i=n; i<bakN; ++i) {
					if (n+matched[i-n]<bakN && ct1[i]!=pt[n+matched[i-n]]) {
						ok = false;
						break;
					}
				}
				n = bakN;
				if (ok) {
// 					cout << "K: " << k << endl;
// 					cout << pt << endl << ct1 << endl << ct2 << endl;
// 					for (int i=0; i<k; ++i) cout << matched[i] << ' ';
// 					cout << endl;

					for (int i=0; i<strlen(ct2); i+=k) {
						for (int j=0; j<k; ++j)
							if (i+matched[j]>=strlen(ct2)) cout << "?";
							else cout << ct2[i+matched[j]];
					}
					cout << endl;
					break;
				}
			}
		}
		n = bakN;
		if (ok) break;
	}
	if (!ok) cout << ct2 << endl;
}

int main(void)
{
	while (true) {
		gets(pt);
		if (pt[0] == '#') break;
		gets(ct1);
		gets(ct2);
		findPerm();
	}

	return 0;
}